<?php
namespace app\manage\controller;

class SystemRecord extends Base
{
    public function index(){
        if(request()->isAjax()){
            $page = input('page');
            $limit = input('limit');
            $id = input('id');
            $adminId = input('admin_id');

            $where['input'] = ['<>', '[]'];
            $where2['input'] = ['not like', '%page%'];
            !empty($id) && $where['id'] = $id;
            !empty($adminId) && $where['admin_id'] = $adminId;

            if( ! $count=model('SystemRecord')->where($where)->where($where2)->count() ){
                $this->layTable();
            }

            $select = model('SystemRecord')
                ->where($where)
                ->where($where2)
                ->limit(($page-1)*$limit, $limit)
                ->order('id desc')
                ->select();

            $adminIdMark = changeValKey('SystemAdmin', 'id', 'remark');
            $data = [];

            $privilegeUrlName = changeValKey('SystemPrivilegeNew', 'url', 'pri_name');
            $allowList = [
                'Base/getServer' => '其他 =》 获取区服',
                'Base/upload' => '其他 =》 上传文件',
                'Index/index' => '其他 =》 后台首页',
                'Index/welcome' => '其他 =》 欢迎页',
                'Index/lock' => '其他 =》 锁屏',
                'Index/feedback' => '其他 =》 问题反馈',
                'Index/history' => '其他 =》 更新历史',
                'Index/quit' => '其他 =》 退出登录',
            ];
            $privilegeUrlPid = changeValKey('SystemPrivilegeNew', 'url', 'pid');
            $privilegeIdName = changeValKey('SystemPrivilegeNew', 'id', 'pri_name');
            foreach ($select as $k=>$v){
                if(array_key_exists($v['url'], $allowList)){
                    $url = $allowList[ $v['url'] ];
                }else{
                    $url = $privilegeIdName[ $privilegeUrlPid[ $v['url'] ] ] . ' =》' . $privilegeUrlName[ $v['url'] ];
                }

                $data[] = [
                    'id' => $v['id'],
                    'admin_id' => $adminIdMark[ $v['admin_id'] ],
                    'url' => $url,
                    'input' => $v['input'],
                    'add_time' => $v['add_time'],
                ];
            }

            $this->layTable(0, '操作记录列表', $data, $count);
        }else{
            $adminId = model('SystemAdmin')->where('status', 1)->order('id desc')->select();
            return view('', ['admin_id'=>$adminId]);
        }
    }

}